home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / vgballse.zip / VGBALLSE.PRG < prev   
Text File  |  1993-01-27  |  6KB  |  237 lines

  1. -AUTHORS
  2. Greg Donohoe
  3. -AUTHORS_END
  4.  
  5. -SHORT_PROG_DESCRIPTION
  6. Creates a image of a ball with the origin at the center
  7. -SHORT_PROG_DESCRIPTION_END
  8.  
  9. -SHORT_LIB_DESCRIPTION
  10. Creates a image of a ball with the origin at the center
  11. -SHORT_LIB_DESCRIPTION_END
  12.  
  13. -MAN1_LONG_DESCRIPTION
  14. .I vgballse
  15. creates an image of a ball.  The background intensity is set by the
  16. -b argument.
  17. The ball can be placed anywhere, and is NOT required to lie
  18. completely within the image boundaries.  The origin of the structuring
  19. elment is placed at the center of the sphere.
  20. .LP
  21. The position of the center of the circle and its diameter can all be
  22. specified as floating point numbers, allowing sub-pixel positioning of
  23. the circle.
  24. .LP
  25. The trigger input can be used to cause
  26. .I vgballse
  27. to re-execute when used inside cantata. No image is read from this input.
  28. -MAN1_LONG_DESCRIPTION_END
  29.  
  30. -MAN1_EXAMPLES
  31. vgballse -r 32 -c 32 -b 3.5 -f 100 -x 32 -y 16 -d 32 -t int
  32. .LP
  33. Creates a 32x32 image of type INT, with the background level at 3.5 and
  34. the foreground at 107.5. The circle lies in this case halfway off the image
  35. to the right.  The diameter of the circle is 32 pixels.
  36. -MAN1_EXAMPLES_END
  37.  
  38. -MAN1_RESTRICTIONS
  39. .I vgballse
  40. will generate only BYTE or FLOAT images.
  41. -MAN1_RESTRICTIONS_END
  42.  
  43. -MAN1_SEE_ALSO
  44. -MAN1_SEE_ALSO_END
  45.  
  46. -MAN3_LONG_DESCRIPTION
  47. .I lvgballse
  48. creates an image of a ball.  The background intensity is set by the
  49. -b argument. The foreground or circle intensity is set by the -f argument.
  50. The circle can be placed anywhere, and is NOT required to lie
  51. completely within the image boundaries.  The origin of the structuring
  52. elment is placed at the center of the sphere.
  53. .LP
  54. The position of the center of the circle and its diameter can all be
  55. specified as floating point numbers, allowing sub-pixel positioning of
  56. the circle.
  57. -MAN3_LONG_DESCRIPTION_END
  58.  
  59. -MAN3_RESTRICTIONS
  60. .I lvgballse
  61. will generate only INT or BYTE images.
  62. -MAN3_RESTRICTIONS_END
  63.  
  64. -MAN3_SEE_ALSO
  65. -MAN3_SEE_ALSO_END
  66.  
  67. -USAGE_ADDITIONS
  68. -USAGE_ADDITIONS_END
  69.  
  70. -INCLUDE_INCLUDES
  71. -INCLUDE_INCLUDES_END
  72.  
  73. -INCLUDE_ADDITIONS
  74. -INCLUDE_ADDITIONS_END
  75.  
  76. -INCLUDE_MACROS
  77. -INCLUDE_MACROS_END
  78.  
  79. -MAIN_VARIABLE_LIST
  80. struct xvimage *image;
  81. int type;
  82. -MAIN_VARIABLE_LIST_END
  83.  
  84. -MAIN_BEFORE_LIB_CALL
  85. if(check_args())exit(1);
  86.  
  87. if(!vget_type(&type, vgballse->t_toggle)){
  88.    fprintf(stderr,"vgballse:  Invalid data type specified\n");
  89.    exit(1);
  90. }
  91.  
  92. if(type!=VFF_TYP_1_BYTE && type!=VFF_TYP_4_BYTE){
  93.    fprintf(stderr,"%s:  Illegal image data type specified.\n",program);
  94.    exit(1);
  95. }
  96.  
  97. -MAIN_BEFORE_LIB_CALL_END
  98.  
  99. -MAIN_LIBRARY_CALL
  100. if(! lvgballse( &image, type, vgballse->b_float, vgballse->x_float,vgballse->y_float, vgballse->origin_logic, vgballse->d_float))
  101.   {
  102.       (void) fprintf(stderr, "lvgballse Failed\n");
  103.       exit(1);
  104.   }
  105. -MAIN_LIBRARY_CALL_END
  106.  
  107. -MAIN_AFTER_LIB_CALL
  108. writeimage(vgballse->o_file,image);
  109. -MAIN_AFTER_LIB_CALL_END
  110.  
  111. -LIBRARY_INCLUDES
  112. -LIBRARY_INCLUDES_END
  113.  
  114. -LIBRARY_INPUT
  115. .IP "image" 15
  116. input image structure
  117. .IP "type" 15
  118. the data storage type of the resulting image
  119. .IP "bgnd" 15
  120. the background intensity
  121. .IP "x" 15
  122. the X coordinate of the origin
  123. .IP "y" 15
  124. the Y coordinate of the origin
  125. .IP "origin"
  126. automatic or user-selected origin
  127. .IP "d" 15
  128. diameter of circle (in pixels) 
  129. -LIBRARY_INPUT_END
  130.  
  131. -LIBRARY_OUTPUT
  132. .IP "image" 15
  133. holds the resulting output image.
  134. -LIBRARY_OUTPUT_END
  135.  
  136. -LIBRARY_DEF
  137. int
  138. lvgballse (image,  type, bgnd,  x, y, origin, d)
  139. struct xvimage **image;
  140. int type;
  141. float bgnd,x,y,d;
  142. int origin;
  143. -LIBRARY_DEF_END
  144.  
  145. -LIBRARY_CODE
  146. {
  147.   int i,j;
  148.   unsigned char *cpixel;
  149.   int *ipixel;
  150.   float r;
  151.   struct xvimage *img, *createimage();
  152.   int xorg, yorg;
  153.   int rows, cols;
  154.  
  155.   rows = d;
  156.   cols = d;
  157.  
  158.   img   = createimage((unsigned long) rows,  /* number of rows */
  159.                      (unsigned long) cols,   /* number of columns */
  160.                      (unsigned long) type,   /* data storage type */
  161.                      (unsigned long) 1,      /* num_of_images */
  162.                      (unsigned long) 1,      /* num_data_bands */
  163.                      "created by vgballse",    /* comment */
  164.                      (unsigned long) 0,      /* map_row_size */
  165.                      (unsigned long) 0,      /* map_col_size */
  166.                      (unsigned long)
  167.                      VFF_MS_NONE,            /* map_scheme */
  168.                      (unsigned long)
  169.                      VFF_MAPTYP_NONE,        /* map_storage_type */
  170.                      (unsigned long)
  171.                      VFF_LOC_IMPLICIT,       /* location_type */
  172.                      (unsigned long) 0);     /* location_dim */
  173.  
  174.  
  175.   if (img == NULL)
  176.     {
  177.       fprintf(stderr,"lvgballse: Unable to allocate new image!\n");
  178.       *image = NULL;
  179.       return(0);
  180.     }
  181.  
  182.   *image = img;
  183.   r = d/2.0;
  184.   r = r*r;
  185.  
  186.   /* Set the SE origin:  either center it,  or accept user */
  187.   /*  values */
  188.   if (!origin) {
  189.      xorg = (int)d/2.0;
  190.      yorg = (int)d/2.0;
  191.   }
  192.   else {
  193.      xorg = x;
  194.      yorg = y;
  195.   }
  196.  
  197.  
  198.  img->ispare1 = -xorg;
  199.  img->ispare2 = -yorg;
  200.  
  201.  x = (int)d/2.0;
  202.  y = (int)d/2.0;
  203.  
  204.   switch(type)
  205.     {
  206.       case VFF_TYP_1_BYTE:
  207.         cpixel = (unsigned char *)(img->imagedata);
  208.         for (i=0; i<rows; i++)
  209.           for (j=0; j<cols; j++)
  210.             if (((i-y)*(i-y)+(j-x)*(j-x)) <= r)
  211.                   *cpixel++ = 
  212.                  (unsigned char)(sqrt(r - (i-y)*(i-y) - (j-x)*(j-x) + .5));
  213.             else *cpixel++ = bgnd;
  214.         break;
  215.       case VFF_TYP_4_BYTE:
  216.         ipixel = (int *)(img->imagedata);
  217.         for (i=0; i<rows; i++)
  218.           for (j=0; j<cols; j++)
  219.             if ((i-y)*(i-y)+(j-x)*(j-x) <= r)
  220.                   *ipixel++ = (int)(sqrt(r - (i-y)*(i-y) - (j-x)*(j-x) + .5));
  221.             else *ipixel++ = bgnd;
  222.         break;
  223.       default:
  224.         fprintf(stderr,"lvgballse: Unsupported data storage type requested\n");
  225.         fprintf(stderr,"         Supported types: INT and BYTE\n");
  226.         return(0);
  227.     }
  228.  
  229.   return(1);
  230. }
  231. -LIBRARY_CODE_END
  232.  
  233. -LIBRARY_MODS
  234.  
  235. -LIBRARY_MODS_END
  236.  
  237.